﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using GaiNo.WS.Core.Services;
using Microsoft.Practices.Unity;
using GaiNo.Core.Services;
using GaiNo.Core.Helpers;
using GaiNo.WS.Core.Models;
using GaiNo.Core.Data;
using GaiNo.Core.Extensions;

namespace GaiNo.WS.Core.Controllers
{
    public class HomeController : Controller
    {
        ISite _site = null;
        ISiteList _sitelist = null;
        IPager _pager = null;
        public HomeController(ISite site, ISiteList sitelist, IPager pager)
        {
            _site = site;
            _sitelist = sitelist;
            _pager = pager;
        }
        public ActionResult Index()
        {
            return View(_site.GetByID(ConfigHelper.GetInt32("SITE_ID").GetValueOrDefault()));
        }
        [HttpPost]
        public ActionResult Index(SiteEntity entity)
        {
            SiteEntity old = _site.GetByID(ConfigHelper.GetInt32("SITE_ID").GetValueOrDefault());
            old.Title = entity.Title;
            old.Update();

            return View(old);
        }
        public ActionResult List(int? page)
        {
            ////分页过程
            int pageSize = 20;
            int pageIndex = page.GetValueOrDefault();
            _pager.PageSize = pageSize;
            _pager.PageIndex = pageIndex;
            _sitelist.Pager = _pager;
            var list = _sitelist.GetList();

            int recordCount = _pager.GetCount();
            //分页数据
            PageOfList<SiteEntity> pList = new PageOfList<SiteEntity>(list, pageIndex, pageSize, recordCount);
            return View(pList);
        }
    }
}
